#include "ExpressionAll.h"

ExpressionAll::ExpressionAll()
{
    m_bFirst = true;
    m_mapOpr.clear();
}

ExpressionAll::~ExpressionAll()
{
    m_mapOpr.clear();
}

//注册操作符;
void ExpressionAll::RegisterOpr(char m_char, Expression* pExpressionAll)
{
    if (NULL == pExpressionAll)
    {
        return;
    }
    m_mapOpr[m_char] = pExpressionAll;
}
//解析操作;
uint64_t ExpressionAll::Interpreter(ContextInterpreter& context)
{
    if (m_bFirst)
    {
        //拿到第一数字;
        m_bFirst = false;
        uint64_t uNextNumber = FindNextNumber(context);
        context.m_uValue = context.m_uValue + uNextNumber;
    }

    QChar uNextOpr = FindNextOpreation(context);
    char chOpr = uNextOpr.toLatin1();
    auto iter = m_mapOpr.find(chOpr);
    if (iter != m_mapOpr.end())
    {
        Expression* pExpression = m_mapOpr[chOpr];
        if (pExpression)
        {
            pExpression->Interpreter(context);
        }
    }
    
    return context.m_uValue;
}
